package com.demo.connectdbtest.module.dict.controller;

import com.alibaba.fastjson.JSONObject;
import com.demo.connectdbtest.module.dict.domain.StatGoldConsumeStatistics;
import com.demo.connectdbtest.module.dict.meMapper.StatGoldConsumeStatisticsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/statGoldConsume")
public class StatGoldConsumeController {
    private static final Logger log = LoggerFactory.getLogger(DictionaryController.class);


    @Autowired
    private StatGoldConsumeStatisticsMapper statGoldConsumeStatisticsMapper;

    @GetMapping("/addConsumeData")
    public String getUserConsumeData() {
        ArrayList<StatGoldConsumeStatistics> list = new ArrayList<>();
        try {
            StatGoldConsumeStatistics add = new StatGoldConsumeStatistics();
            StatGoldConsumeStatistics add1 = new StatGoldConsumeStatistics();
            add1.setUid(1L);
            add1.setUuid(10L);
            add1.setTotalConsumeGold(1L);
            add1.setCreateTime(System.currentTimeMillis());
            add.setUid(2L);
            add.setUuid(20L);
            add.setTotalConsumeGold(2L);
            add.setCreateTime(System.currentTimeMillis());
            list.add(add1);
            list.add(add);
            statGoldConsumeStatisticsMapper.addBatchConsumeRecord(list);
            JSONObject.toJSONString(list);
        } catch (Exception e) {
            log.error("getMogonData", e);
            return "fail" + e.toString();
        }
        return "ok" + JSONObject.toJSONString(list).toString();
    }


    @GetMapping("/updateConsumeData")
    public String updateConsumeData() {
        ArrayList<StatGoldConsumeStatistics> list = new ArrayList<>();
        try {
            StatGoldConsumeStatistics add = new StatGoldConsumeStatistics();
            StatGoldConsumeStatistics add1 = new StatGoldConsumeStatistics();
            add1.setUid(1L);
            add1.setUuid(10L);
            add1.setTotalConsumeGold(10L);
            add1.setUpdateTime(System.currentTimeMillis());
            add.setUid(2L);
            add.setUuid(20L);
            add.setTotalConsumeGold(20L);
            add.setUpdateTime(System.currentTimeMillis());
            list.add(add1);
            list.add(add);
            list.forEach(item-> System.out.println(item));
            statGoldConsumeStatisticsMapper.updateBatchConsumeByUid(list);
            JSONObject.toJSONString(list);
        } catch (Exception e) {
            log.error("getMogonData", e);
            return "fail" + e.toString();
        }
        return "ok" + JSONObject.toJSONString(list).toString();
    }

}
